
#ifndef __KTVBLOWFISH_H__
#define __KTVBLOWFISH_H__

	// blowfish.h     interface file for blowfish.cpp
	// _THE BLOWFISH ENCRYPTION ALGORITHM_
	// by Bruce Schneier
	// Revised code--3/20/94
	// Converted to C++ class 5/96, Jim Conger

	#define MAXKEYBYTES 	56		// 448 bits max
	#define NPASS           16		// SBox passes

	class CKtvBlowFish:public CKtvObject{
	public:	
		static UINT32		GetOutputLength (UINT32 lInputLong) ;	
	public:
		CKtvBlowFish();
		virtual ~CKtvBlowFish();
		
		void 		Initialize (BYTE key[], int keybytes) ;
		UINT32		Encode (BYTE * pInput, BYTE * pOutput, UINT32 lSize) ;
		void		Decode (const BYTE * pInput, BYTE * pOutput, UINT32 lSize) ;
	private:
		UINT32 		* PArray ;
		UINT32		(* SBoxes)[256];
		void 		Blowfish_encipher (UINT32 *xl, UINT32 *xr) ;
		void 		Blowfish_decipher (UINT32 *xl, UINT32 *xr) ;	
	};

		
	// choose a byte order for your hardware
	#define ORDER_DCBA	// chosing Intel in this case

	#ifdef ORDER_DCBA  	// DCBA - little endian - intel
		union aword {
		  UINT32 dword;
		  BYTE byte [4];
		  struct {
		    unsigned int byte3:8;
		    unsigned int byte2:8;
		    unsigned int byte1:8;
		    unsigned int byte0:8;
		  } w;
		};
	#endif

	#ifdef ORDER_ABCD  	// ABCD - big endian - motorola
		union aword {
		  UINT32 dword;
		  BYTE byte [4];
		  struct {
		    unsigned int byte0:8;
		    unsigned int byte1:8;
		    unsigned int byte2:8;
		    unsigned int byte3:8;
		  } w;
		};
	#endif

	#ifdef ORDER_BADC  	// BADC - vax
		union aword {
		  UINT32 dword;
		  BYTE byte [4];
		  struct {
		    unsigned int byte1:8;
		    unsigned int byte0:8;
		    unsigned int byte3:8;
		    unsigned int byte2:8;
		  } w;
	};
	#endif

#endif //#ifndef __KTVBLOWFISH_H__

